﻿namespace Maple.Weixin.MP.Entities.Messages
{
    public class ResponseVoice : ResponseMedia, IResponseService
    {
        private string mediaId;

        internal ResponseVoice() { }

        public ResponseVoice(string mediaId) {
            this.mediaId = mediaId;
        }

        public static ResponseVoice CreateByFile(string fileName, out string result)
        {
            var responseVoice = new ResponseVoice();
            var mediaId = responseVoice.UploadMedia(fileName, out result);
            if (string.IsNullOrEmpty(mediaId))
                return null;
            responseVoice.mediaId = mediaId;
            return responseVoice;
        }

        #region Implementation of IResponseService

        public ResponseMessageBase Handle(RequestMessageBase requestMessage) {
            var responseMessage = requestMessage.CreateVoiceResponse(mediaId);
            return responseMessage;
        }

        #endregion

        #region Overrides of ResponseMedia

        protected override UploadMediaType MediaType {
            get { return UploadMediaType.Voice; }
        }

        #endregion
    }
}
